﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm {
    public class Common {
        /// <summary>
        /// 获取数组相同元素个数
        /// </summary>
        public void GetSameCount() {
            List<int> value = new List<int>() { 2,2,5,52,92,5 };
            var source = value.GroupBy(t => t).Select(t => new { count = t.Count(),key = t.Key }).ToArray();
            foreach(var s in source) {
                Console.WriteLine(s.key + ":" + s.count);
            }
        }

        /// <summary>
        /// 冒泡排序法
        /// </summary>
        /// <param name="lis"></param>
        /// <returns></returns>
        public int[] BubbleSort(object lis) {
            int temp;
            int[] arrSort = lis as int[];
            for(int i = 0;i < arrSort.Length;i++) {
                for(int j = i + 1;j < arrSort.Length;j++) {
                    if(arrSort[j] < arrSort[i]) {
                        temp = arrSort[j];
                        arrSort[j] = arrSort[i];
                        arrSort[i] = temp;
                    }
                }
            }
            return arrSort;
        }

    }
}
